package com.css.apps.base.sysjob.action;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.css.apps.base.role.action.RoleItem;
import com.css.apps.base.role.model.SRole;
import com.css.core.configuration.Environment;
import com.css.util.Ajax;
import com.css.util.ListUtil;
import com.css.util.Messages;
import com.css.util.StringHelper;
import com.css.webbase.webwork.action.AdminAction;
import com.opensymphony.xwork.Action;

public class DirSysRoles extends AdminAction{
	private static final long serialVersionUID = 1L;
	private static Log log = LogFactory.getLog(DirSysRoles.class);
	private String sysId;
	
	@Override
	protected String adminGo() {
		if(StringHelper.isEmpty(sysId)){
			result = Ajax.JSONResult(Environment.RESULT_CODE_ERROR, Messages.getString("systemMsg.fieldEmpty"));
			return ERROR;
		}
		try {
			List<SRole> listSysRole = RoleItem.getSRoleBySysId(sysId);
			if(ListUtil.isLstEmpty(listSysRole)){
				result = Ajax.JSONResult(Environment.RESULT_CODE_ERROR, Messages.getString("systemMsg.notSysRole"));
				return ERROR;
			}
			result = Ajax.JSONResult(Environment.RESULT_CODE_SUCCESS, Messages.getString("systemMsg.success"),listSysRole);
			return SUCCESS;
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			setMessage(Messages.getString("systemMsg.exception"));
			return Action.ERROR;
		}
	}
	
	public String getSysId() {
		return sysId;
	}
	
	public void setSysId(String sysId) {
		this.sysId = sysId;
	}
}